package com.jinsi.controller.tang;

import com.jinsi.constant.TangConstant;
import com.jinsi.pojo.Commodity;

import com.jinsi.pojo.SyUser;
import com.jinsi.service.tang.JournalService;
import com.jinsi.service.tang.ProductEditService;
import com.jinsi.util.R;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * 修改编辑商品类
 * @author 唐文博
 * @Date 2022-08-05
 */
@RestController
@RequestMapping("/edit")
@Slf4j
public class ProductEditController {
    @Autowired
    private ProductEditService productEditService;

    @Autowired
    private JournalService journalService;

    /**
     * 修改表数据接口
     * @param
     * @param session
     * @return
     */
    @RequestMapping("/update")
    public R updateStudent(Integer commodityId, Integer commodityCode,
                           String commodityName, String commodityImage,
                           Integer classifyId, Integer currentPrice,
                           String commodityDetails,String commodityLabel,
                           String searchKeywords, Date createDate,HttpSession session) {
        Date date = new Date();
        SyUser user = (SyUser) session.getAttribute("user");
        try {
            log.info("编辑商品记录日志:[开始], 商品id：{},用户编号：{}," +
                    "商品名称：{},商品路径：{},商品分类id：{},商品价格：{}," +
                    "用户id：{}",commodityId,commodityCode,commodityName,
                    commodityImage,classifyId,currentPrice,session);
            productEditService.editCommodity(commodityId,commodityCode,commodityName,
                    commodityImage,classifyId,currentPrice,commodityDetails,commodityLabel,
                    searchKeywords,createDate);
            log.info("编辑商品记录日志: [开始] 结果：{}","开始");
            journalService.addCkJournal(user.getUserName(),TangConstant.PRODUCT_LIST,
                    date,TangConstant.PRODUCT_DEIT,TangConstant.PRODUCT_PRODUCTDEIT,
                    TangConstant.COMMODITY_ISDEL);
            log.info("编辑商品记录日志: [结束] 结果：{}","成功");
            log.info("修改商品信息: [结束] 结果：{}","成功");
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("修改商品信息: [失败]", e);
            return R.error();
        }
    }
}